package ar.com.solidussource.howmuchmobile.activities;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.*;
import ar.com.solidussource.howmuchmobile.R;
import ar.com.solidussource.howmuchmobile.activities.generic.BaseActivity;
import ar.com.solidussource.howmuchmobile.activities.maps.HowMuchMapActivity;

/**
 * Created with IntelliJ IDEA.
 * User: FT31270775
 * Date: 06/11/12
 * Time: 11:54
 * To change this template use File | Settings | File Templates.
 */
public class MainActivity extends BaseActivity {
    private String data[] = new String[]{"Ubicacion","Productos","Mapa", "AYUDA"};
    private Integer icon[] = new Integer[]{R.drawable.home, R.drawable.cart, R.drawable.map, R.drawable.help};

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        LayoutInflater inflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View v = (View) inflater.inflate(R.layout.main_menu, null);

        ListView lstOpciones = (ListView)v.findViewById(R.id.menuList);

        lstOpciones.setOnItemClickListener(new MainMenuOnItemClickListener());

        lstOpciones.setAdapter(new MainMenuArrayAdapter(this));

        setContent(v);
    }

    class MainMenuArrayAdapter extends ArrayAdapter<String> {

        Activity context;

        MainMenuArrayAdapter(Activity context) {
            super(context, R.layout.main_menu_row, data);
            this.context = context;
        }

        public View getView(int position, View convertView, ViewGroup parent) {
            LayoutInflater inflater = context.getLayoutInflater();
            View item = inflater.inflate(R.layout.main_menu_row, null);

            TextView lblTitulo = (TextView) item.findViewById(R.id.mainMenu);
            lblTitulo.setText(data[position]);

            ImageView img = (ImageView) item.findViewById(R.id.productCheck);

            img.setImageResource(icon[position]);

            return(item);
        }

    }

    class MainMenuOnItemClickListener implements AdapterView.OnItemClickListener {

        public void onItemClick(AdapterView<?> a, View v, int position, long id) {
            if(position == 0){
                Intent intent = new Intent(MainActivity.this, UbicacionMenu.class);
                //intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
                startActivity(intent);
            }
            if(position == 1){
                Intent intent = new Intent(MainActivity.this, ProductcategoryListActivity.class);
                startActivity(intent);
            }
            if(position == 2){
                Intent intent = new Intent(MainActivity.this, HowMuchMapActivity.class);
                startActivity(intent);
            }
        }

    }

}